//vite.config.ts
import { loadEnv, defineConfig } from 'vite';
import uni from '@dcloudio/vite-plugin-uni';
import path from 'path';
import AutoImport from 'unplugin-auto-import/vite'
import uniReadPagesV3Plugin from './common/router/utils/uni-read-pages-v3';


export default defineConfig(({ mode }) => {
	const env = loadEnv(mode, __dirname, 'NX_');

	return {
		base: './',
		envPrefix: "NX_",
		plugins: [
			uni(),
			uniReadPagesV3Plugin({
				pagesJsonDir: path.resolve(__dirname, './pages.json'),
				includes: ['path', 'aliasPath', 'name', 'meta'],
			}),
			AutoImport({
				imports: [
					'vue',
					'uni-app',
					'pinia',
				],
				dirs: ['./common/store/modules'],
			})
		],
		server: {
			host: true,
			// open: true,
			port: env.NX_DEV_PORT,
			hmr: {
				overlay: true,
			},
		},
	};
});